﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using BLToolkit.Data.Linq;
using BLToolkit.Data;

namespace DAL
{
    public class HangHoaRepository : IHangHoaRepository
    {
        private  DbManager db = new DbManager("QuanLyBilliards");
       
        public HangHoa GetByMaHangHoa(string maHH)
        {
            return db.GetTable<HangHoa>().SingleOrDefault(tk => tk.MaHH == maHH);
        }

        public IQueryable<HangHoa> GetAll()
        {
            return db.GetTable<HangHoa>();
        }

        public bool AddNew(HangHoa hangHoa)
        {
            return db.Insert(hangHoa) > 0;
        }

        public bool Update(HangHoa hangHoa)
        {
            return db.Update(hangHoa) > 0;
        }

        public bool Delete(HangHoa hangHoa)
        {
            return db.Delete(hangHoa)>0;
        }
        public IQueryable<HangHoa> TimHangHoaTheoSoLuong(int soLuong)
        {
            return db.GetTable<HangHoa>().Where(so => so.SoLuong == soLuong);
        }

        //thuy
        public  IQueryable<HangHoa> TimHangHoaTheoTen(string tenhh)
        { 
          return db.GetTable<HangHoa>().Where(ten=>ten.TenHH.Contains(tenhh));
        }
        public HangHoa TimTheoTen(string ten)
        {
            return db.GetTable<HangHoa>().SingleOrDefault(hh => hh.TenHH == ten);
        }
        
        public IQueryable<HangHoa> TimHHTheoNhaCungCap(String macc)
        {
            return db.GetTable<HangHoa>().Where(tk => tk.NhaCC == macc);
        }
        public IQueryable<HangHoa> TimHHTheoNgayhetHan(string ngay)
        {
            return db.GetTable<HangHoa>().Where(tk=> tk.NgayHethan.CompareTo(ngay)==0);
        }



        void IHangHoaRepository.AddNew(HangHoa hangHoa)
        {
            throw new NotImplementedException();
        }

        void IHangHoaRepository.Update(HangHoa hangHoa)
        {
            throw new NotImplementedException();
        }

        void IHangHoaRepository.Delete(HangHoa hangHoa)
        {
            throw new NotImplementedException();
        }


        public IQueryable<HangHoa> TimHangHoaTheoLoai(string loai)
        {
            return db.GetTable<HangHoa>().Where(hh => hh.LoaiHH == loai);
        }
    }
}
